//
//  WSAlbumDetailTableViewCell.m
//  GroupFourFM
//
//  Created by 王鑫 on 15/12/24.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WSAlbumDetailTableViewCell.h"

@interface WSAlbumDetailTableViewCell ()

@property(nonatomic,retain)UIImageView *trackPic;
@property(nonatomic,retain)WSBaseCollectionLabel *trackTitle;
@property(nonatomic,retain)UILabel *trackDigest;
@property(nonatomic,retain)UILabel *playCount;
@property(nonatomic,retain)UILabel *likes;
@property(nonatomic,retain)UILabel *duration;
@property(nonatomic,retain)UILabel *Comments;
@property(nonatomic,retain)UIButton *playButton;
@property(nonatomic,retain)UIImageView *iconImageV;
@property(nonatomic,retain)UIImageView *iconLikeV;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation WSAlbumDetailTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubViews];
    }
    
    return self;
}

- (void)createSubViews
{
    self.trackPic = [[UIImageView alloc] init];
    self.trackPic.backgroundColor = CLEAR;
    self.trackPic.layer.masksToBounds = YES;
    self.trackPic.layer.cornerRadius = 32.5;
    [self.contentView addSubview:self.trackPic];
    [self.trackPic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.mas_equalTo(@15);
        make.bottom.mas_equalTo(@-40);
        make.width.equalTo(self.contentView.mas_height).offset(-55);
    }];
    
    self.trackTitle = [[WSBaseCollectionLabel alloc] init];
    self.trackTitle.font = [UIFont systemFontOfSize:18 weight:0];
    self.trackTitle.numberOfLines = 2;
    self.trackTitle.backgroundColor = CLEAR;
    [self.contentView addSubview:self.trackTitle];
    [self.trackTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.trackPic.mas_right).offset(10);
        make.top.equalTo(self.trackPic);
        make.height.mas_equalTo(50);
        make.right.mas_equalTo(-40);
    }];
    

    self.trackDigest = [[UILabel alloc] init];
    self.trackDigest.backgroundColor = CLEAR;
    self.trackDigest.font = [UIFont systemFontOfSize:15 weight:0];
    [self.contentView addSubview:self.trackDigest];
    self.trackDigest.textColor = [UIColor lightGrayColor];
    [self.trackDigest mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.trackTitle);
        make.top.mas_equalTo(self.trackTitle.mas_bottom).offset(5);
        make.right.mas_equalTo(self.trackTitle);
        make.height.mas_equalTo(15);
    }];
    
    self.iconImageV = [[UIImageView alloc] init];
    self.iconImageV.backgroundColor = CLEAR;
    self.iconImageV.tintColor = [UIColor colorWithRed:0.71 green:0.71 blue:0.71 alpha:1];
    self.iconImageV.image = [[UIImage imageNamed:@"album_playCountLogo@3x"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    [self.contentView addSubview:self.iconImageV];
    [self.iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.trackTitle);
        make.top.mas_equalTo(self.trackDigest.mas_bottom).offset(10);
        make.width.mas_equalTo(SCREEN_HEIGHT*0.013);
        make.height.mas_equalTo(SCREEN_HEIGHT*0.015);
        
    }];
    
    self.playCount = [[UILabel alloc] init];
    self.playCount.backgroundColor = CLEAR;
    self.playCount.font = [UIFont systemFontOfSize:13 weight:0];
    [self.contentView addSubview:self.playCount];
    self.playCount.textAlignment = NSTextAlignmentLeft;
    self.playCount.textColor = [UIColor lightGrayColor];
    [self.playCount mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.iconImageV.mas_right).offset(2);
        make.top.mas_equalTo(self.iconImageV);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(10);
    }];
    

    self.iconLikeV = [[UIImageView alloc] init];
    self.iconLikeV.backgroundColor = CLEAR;
    self.iconLikeV.image = [UIImage imageNamed:@"find_emotion@3x"];
    [self.contentView addSubview:self.iconLikeV];
    [self.iconLikeV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.playCount.mas_right);
        make.top.equalTo(self.iconImageV);
        make.width.height.mas_equalTo(SCREEN_HEIGHT * 0.02);
    }];
    
 
    self.duration = [[UILabel alloc] init];
    self.duration.backgroundColor = CLEAR;
    self.duration.font = [UIFont systemFontOfSize:13 weight:0];
    [self.contentView addSubview:self.duration];
    self.duration.textAlignment = NSTextAlignmentLeft;
    self.duration.textColor = [UIColor lightGrayColor];
    [self.duration mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.iconLikeV.mas_right).offset(2);
        make.top.mas_equalTo(self.iconImageV);
        make.height.mas_equalTo(self.playCount);
        make.right.mas_equalTo(self.contentView).offset(-10);
    }];

    self.lineView = [[UIView alloc] init];
    self.lineView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    [self.contentView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.trackTitle);
        make.bottom.equalTo(self.contentView);
        make.right.mas_equalTo(@0);
        make.height.mas_equalTo(@1);
    }];
//    self.lineView.hidden = !self.isShowLine;
}

-(void)setTrackModel:(WSTrackModel *)trackModel
{
    NSURL *url = [NSURL URLWithString:trackModel.coverSmall];
    [self.trackPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_CIRCLE];
    self.trackTitle.text = trackModel.title;
    [self.trackTitle sizeToFit];
    
    self.trackDigest.text = [NSString stringWithFormat:@"by %@", trackModel.nickname];
    self.playCount.text = [NSString stringWithFormat:@"%.2f万", (CGFloat)trackModel.playtimes/10000];
    self.duration.text = [NSString stringWithFormat:@"%ld人想听", trackModel.likes];
}

@end
